// $ANTLR 3.2 Sep 23, 2009 12:02:23 /home/hasitha/Desktop/ToSend/SampleProject/src/main/java/a.g 2013-03-29 21:19:29

package lk.uom.cse.adarchi.dlxasm;
  import org.antlr.stringtemplate.*;


import org.antlr.runtime.*;
import java.util.Stack;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.util.HashMap;
import org.antlr.stringtemplate.*;
import org.antlr.stringtemplate.language.*;
import java.util.HashMap;


public class aParser extends Parser {
    public static final String[] tokenNames = new String[] {
        "<invalid>", "<EOR>", "<DOWN>", "<UP>", "ID", "INT", "WS", "';'", "'('", "','", "')'", "'int'", "'char'", "'{'", "'}'", "'for'", "'while'", "'do'", "'='", "'=='", "'<'", "'+'"
    };
    public static final int T__21=21;
    public static final int T__20=20;
    public static final int INT=5;
    public static final int ID=4;
    public static final int EOF=-1;
    public static final int T__9=9;
    public static final int T__8=8;
    public static final int T__7=7;
    public static final int T__19=19;
    public static final int WS=6;
    public static final int T__16=16;
    public static final int T__15=15;
    public static final int T__18=18;
    public static final int T__17=17;
    public static final int T__12=12;
    public static final int T__11=11;
    public static final int T__14=14;
    public static final int T__13=13;
    public static final int T__10=10;

    // delegates
    // delegators

    protected static class slist_scope {
        List locals;
        List stats;
    }
    protected Stack slist_stack = new Stack();


        public aParser(TokenStream input) {
            this(input, new RecognizerSharedState());
        }
        public aParser(TokenStream input, RecognizerSharedState state) {
            super(input, state);
             
        }
        
    protected StringTemplateGroup templateLib =
      new StringTemplateGroup("aParserTemplates", AngleBracketTemplateLexer.class);

    public void setTemplateLib(StringTemplateGroup templateLib) {
      this.templateLib = templateLib;
    }
    public StringTemplateGroup getTemplateLib() {
      return templateLib;
    }
    /** allows convenient multi-value initialization:
     *  "new STAttrMap().put(...).put(...)"
     */
    public static class STAttrMap extends HashMap {
      public STAttrMap put(String attrName, Object value) {
        super.put(attrName, value);
        return this;
      }
      public STAttrMap put(String attrName, int value) {
        super.put(attrName, new Integer(value));
        return this;
      }
    }

    public String[] getTokenNames() { return aParser.tokenNames; }
    public String getGrammarFileName() { return "/home/hasitha/Desktop/ToSend/SampleProject/src/main/java/a.g"; }


    protected static class program_scope {
        List globals;
        List functions;
    }
    protected Stack program_stack = new Stack();

    public static class program_return extends ParserRuleReturnScope {
        public StringTemplate st;
        public Object getTemplate() { return st; }
        public String toString() { return st==null?null:st.toString(); }
    };

    // $ANTLR start "program"
    // /home/hasitha/Desktop/ToSend/SampleProject/src/main/java/a.g:30:1: program : ( declaration )+ -> program(globals=$program::globalsfunctions=$program::functions);
    public final aParser.program_return program() throws RecognitionException {
        program_stack.push(new program_scope());
        aParser.program_return retval = new aParser.program_return();
        retval.start = input.LT(1);


          ((program_scope)program_stack.peek()).globals = new ArrayList();
          ((program_scope)program_stack.peek()).functions = new ArrayList();


        try {
            // /home/hasitha/Desktop/ToSend/SampleProject/src/main/java/a.g:41:5: ( ( declaration )+ -> program(globals=$program::globalsfunctions=$program::functions))
            // /home/hasitha/Desktop/ToSend/SampleProject/src/main/java/a.g:41:9: ( declaration )+
            {
            // /home/hasitha/Desktop/ToSend/SampleProject/src/main/java/a.g:41:9: ( declaration )+
            int cnt1=0;
            loop1:
            do {
                int alt1=2;
                int LA1_0 = input.LA(1);

                if ( (LA1_0==ID||(LA1_0>=11 && LA1_0<=12)) ) {
                    alt1=1;
                }


                switch (alt1) {
            	case 1 :
            	    // /home/hasitha/Desktop/ToSend/SampleProject/src/main/java/a.g:0:0: declaration
            	    {
            	    pushFollow(FOLLOW_declaration_in_program69);
            	    declaration();

            	    state._fsp--;
            	    if (state.failed) return retval;

            	    }
            	    break;

            	default :
            	    if ( cnt1 >= 1 ) break loop1;
            	    if (state.backtracking>0) {state.failed=true; return retval;}
                        EarlyExitException eee =
                            new EarlyExitException(1, input);
                        throw eee;
                }
                cnt1++;
            } while (true);



            // TEMPLATE REWRITE
            if ( state.backtracking==0 ) {
              // 42:9: -> program(globals=$program::globalsfunctions=$program::functions)
              {
                  retval.st = templateLib.getInstanceOf("program",
                new STAttrMap().put("globals", ((program_scope)program_stack.peek()).globals).put("functions", ((program_scope)program_stack.peek()).functions));
              }

            }
            }

            retval.stop = input.LT(-1);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
            program_stack.pop();
        }
        return retval;
    }
    // $ANTLR end "program"

    public static class declaration_return extends ParserRuleReturnScope {
        public StringTemplate st;
        public Object getTemplate() { return st; }
        public String toString() { return st==null?null:st.toString(); }
    };

    // $ANTLR start "declaration"
    // /home/hasitha/Desktop/ToSend/SampleProject/src/main/java/a.g:45:1: declaration : ( variable | f= function );
    public final aParser.declaration_return declaration() throws RecognitionException {
        aParser.declaration_return retval = new aParser.declaration_return();
        retval.start = input.LT(1);

        aParser.function_return f = null;

        aParser.variable_return variable1 = null;


        try {
            // /home/hasitha/Desktop/ToSend/SampleProject/src/main/java/a.g:46:5: ( variable | f= function )
            int alt2=2;
            switch ( input.LA(1) ) {
            case 11:
                {
                int LA2_1 = input.LA(2);

                if ( (LA2_1==ID) ) {
                    int LA2_4 = input.LA(3);

                    if ( (LA2_4==7) ) {
                        alt2=1;
                    }
                    else if ( (LA2_4==8) ) {
                        alt2=2;
                    }
                    else {
                        if (state.backtracking>0) {state.failed=true; return retval;}
                        NoViableAltException nvae =
                            new NoViableAltException("", 2, 4, input);

                        throw nvae;
                    }
                }
                else {
                    if (state.backtracking>0) {state.failed=true; return retval;}
                    NoViableAltException nvae =
                        new NoViableAltException("", 2, 1, input);

                    throw nvae;
                }
                }
                break;
            case 12:
                {
                int LA2_2 = input.LA(2);

                if ( (LA2_2==ID) ) {
                    int LA2_4 = input.LA(3);

                    if ( (LA2_4==7) ) {
                        alt2=1;
                    }
                    else if ( (LA2_4==8) ) {
                        alt2=2;
                    }
                    else {
                        if (state.backtracking>0) {state.failed=true; return retval;}
                        NoViableAltException nvae =
                            new NoViableAltException("", 2, 4, input);

                        throw nvae;
                    }
                }
                else {
                    if (state.backtracking>0) {state.failed=true; return retval;}
                    NoViableAltException nvae =
                        new NoViableAltException("", 2, 2, input);

                    throw nvae;
                }
                }
                break;
            case ID:
                {
                int LA2_3 = input.LA(2);

                if ( (LA2_3==ID) ) {
                    int LA2_4 = input.LA(3);

                    if ( (LA2_4==7) ) {
                        alt2=1;
                    }
                    else if ( (LA2_4==8) ) {
                        alt2=2;
                    }
                    else {
                        if (state.backtracking>0) {state.failed=true; return retval;}
                        NoViableAltException nvae =
                            new NoViableAltException("", 2, 4, input);

                        throw nvae;
                    }
                }
                else {
                    if (state.backtracking>0) {state.failed=true; return retval;}
                    NoViableAltException nvae =
                        new NoViableAltException("", 2, 3, input);

                    throw nvae;
                }
                }
                break;
            default:
                if (state.backtracking>0) {state.failed=true; return retval;}
                NoViableAltException nvae =
                    new NoViableAltException("", 2, 0, input);

                throw nvae;
            }

            switch (alt2) {
                case 1 :
                    // /home/hasitha/Desktop/ToSend/SampleProject/src/main/java/a.g:46:9: variable
                    {
                    pushFollow(FOLLOW_variable_in_declaration110);
                    variable1=variable();

                    state._fsp--;
                    if (state.failed) return retval;
                    if ( state.backtracking==0 ) {
                      ((program_scope)program_stack.peek()).globals.add((variable1!=null?variable1.st:null));
                    }

                    }
                    break;
                case 2 :
                    // /home/hasitha/Desktop/ToSend/SampleProject/src/main/java/a.g:47:9: f= function
                    {
                    pushFollow(FOLLOW_function_in_declaration126);
                    f=function();

                    state._fsp--;
                    if (state.failed) return retval;
                    if ( state.backtracking==0 ) {
                      ((program_scope)program_stack.peek()).functions.add((f!=null?f.st:null));
                    }

                    }
                    break;

            }
            retval.stop = input.LT(-1);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return retval;
    }
    // $ANTLR end "declaration"

    public static class variable_return extends ParserRuleReturnScope {
        public StringTemplate st;
        public Object getTemplate() { return st; }
        public String toString() { return st==null?null:st.toString(); }
    };

    // $ANTLR start "variable"
    // /home/hasitha/Desktop/ToSend/SampleProject/src/main/java/a.g:53:1: variable : type declarator ';' -> {$function.size()>0 && $function::name==null}? globalVariable(type=$type.stname=$declarator.st) -> variable(type=$type.stname=$declarator.st);
    public final aParser.variable_return variable() throws RecognitionException {
        aParser.variable_return retval = new aParser.variable_return();
        retval.start = input.LT(1);

        aParser.type_return type2 = null;

        aParser.declarator_return declarator3 = null;


        try {
            // /home/hasitha/Desktop/ToSend/SampleProject/src/main/java/a.g:54:5: ( type declarator ';' -> {$function.size()>0 && $function::name==null}? globalVariable(type=$type.stname=$declarator.st) -> variable(type=$type.stname=$declarator.st))
            // /home/hasitha/Desktop/ToSend/SampleProject/src/main/java/a.g:54:9: type declarator ';'
            {
            pushFollow(FOLLOW_type_in_variable150);
            type2=type();

            state._fsp--;
            if (state.failed) return retval;
            pushFollow(FOLLOW_declarator_in_variable152);
            declarator3=declarator();

            state._fsp--;
            if (state.failed) return retval;
            match(input,7,FOLLOW_7_in_variable154); if (state.failed) return retval;


            // TEMPLATE REWRITE
            if ( state.backtracking==0 ) {
              // 55:9: -> {$function.size()>0 && $function::name==null}? globalVariable(type=$type.stname=$declarator.st)
              if (function_stack.size()>0 && ((function_scope)function_stack.peek()).name==null) {
                  retval.st = templateLib.getInstanceOf("globalVariable",
                new STAttrMap().put("type", (type2!=null?type2.st:null)).put("name", (declarator3!=null?declarator3.st:null)));
              }
              else // 57:9: -> variable(type=$type.stname=$declarator.st)
              {
                  retval.st = templateLib.getInstanceOf("variable",
                new STAttrMap().put("type", (type2!=null?type2.st:null)).put("name", (declarator3!=null?declarator3.st:null)));
              }

            }
            }

            retval.stop = input.LT(-1);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return retval;
    }
    // $ANTLR end "variable"

    public static class declarator_return extends ParserRuleReturnScope {
        public StringTemplate st;
        public Object getTemplate() { return st; }
        public String toString() { return st==null?null:st.toString(); }
    };

    // $ANTLR start "declarator"
    // /home/hasitha/Desktop/ToSend/SampleProject/src/main/java/a.g:60:1: declarator : ID -> {new StringTemplate($ID.text)};
    public final aParser.declarator_return declarator() throws RecognitionException {
        aParser.declarator_return retval = new aParser.declarator_return();
        retval.start = input.LT(1);

        Token ID4=null;

        try {
            // /home/hasitha/Desktop/ToSend/SampleProject/src/main/java/a.g:61:5: ( ID -> {new StringTemplate($ID.text)})
            // /home/hasitha/Desktop/ToSend/SampleProject/src/main/java/a.g:61:9: ID
            {
            ID4=(Token)match(input,ID,FOLLOW_ID_in_declarator228); if (state.failed) return retval;


            // TEMPLATE REWRITE
            if ( state.backtracking==0 ) {
              // 61:12: -> {new StringTemplate($ID.text)}
              {
                  retval.st = new StringTemplate((ID4!=null?ID4.getText():null));
              }

            }
            }

            retval.stop = input.LT(-1);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return retval;
    }
    // $ANTLR end "declarator"

    protected static class function_scope {
        String name;
        int loopcount;
    }
    protected Stack function_stack = new Stack();

    public static class function_return extends ParserRuleReturnScope {
        public StringTemplate st;
        public Object getTemplate() { return st; }
        public String toString() { return st==null?null:st.toString(); }
    };

    // $ANTLR start "function"
    // /home/hasitha/Desktop/ToSend/SampleProject/src/main/java/a.g:64:1: function : type ID '(' (p+= formalParameter ( ',' p+= formalParameter )* )? ')' block -> {\"main\".equalsIgnoreCase($function::name)}? main_function(type=$type.stname=\"main\"locals=$slist::localsstats=$slist::statsargs=$p) -> function(type=$type.stname=$function::namelocals=$slist::localsstats=$slist::statsargs=$p);
    public final aParser.function_return function() throws RecognitionException {
        slist_stack.push(new slist_scope());
        function_stack.push(new function_scope());
        aParser.function_return retval = new aParser.function_return();
        retval.start = input.LT(1);

        Token ID5=null;
        List list_p=null;
        aParser.type_return type6 = null;

        RuleReturnScope p = null;

          ((slist_scope)slist_stack.peek()).locals = new ArrayList();
          ((slist_scope)slist_stack.peek()).stats = new ArrayList();

        try {
            // /home/hasitha/Desktop/ToSend/SampleProject/src/main/java/a.g:74:5: ( type ID '(' (p+= formalParameter ( ',' p+= formalParameter )* )? ')' block -> {\"main\".equalsIgnoreCase($function::name)}? main_function(type=$type.stname=\"main\"locals=$slist::localsstats=$slist::statsargs=$p) -> function(type=$type.stname=$function::namelocals=$slist::localsstats=$slist::statsargs=$p))
            // /home/hasitha/Desktop/ToSend/SampleProject/src/main/java/a.g:74:9: type ID '(' (p+= formalParameter ( ',' p+= formalParameter )* )? ')' block
            {
            pushFollow(FOLLOW_type_in_function265);
            type6=type();

            state._fsp--;
            if (state.failed) return retval;
            ID5=(Token)match(input,ID,FOLLOW_ID_in_function267); if (state.failed) return retval;
            if ( state.backtracking==0 ) {
              ((function_scope)function_stack.peek()).name =(ID5!=null?ID5.getText():null);
            }
            match(input,8,FOLLOW_8_in_function279); if (state.failed) return retval;
            // /home/hasitha/Desktop/ToSend/SampleProject/src/main/java/a.g:75:13: (p+= formalParameter ( ',' p+= formalParameter )* )?
            int alt4=2;
            int LA4_0 = input.LA(1);

            if ( (LA4_0==ID||(LA4_0>=11 && LA4_0<=12)) ) {
                alt4=1;
            }
            switch (alt4) {
                case 1 :
                    // /home/hasitha/Desktop/ToSend/SampleProject/src/main/java/a.g:75:15: p+= formalParameter ( ',' p+= formalParameter )*
                    {
                    pushFollow(FOLLOW_formalParameter_in_function285);
                    p=formalParameter();

                    state._fsp--;
                    if (state.failed) return retval;
                    if (list_p==null) list_p=new ArrayList();
                    list_p.add(p.getTemplate());

                    // /home/hasitha/Desktop/ToSend/SampleProject/src/main/java/a.g:75:34: ( ',' p+= formalParameter )*
                    loop3:
                    do {
                        int alt3=2;
                        int LA3_0 = input.LA(1);

                        if ( (LA3_0==9) ) {
                            alt3=1;
                        }


                        switch (alt3) {
                    	case 1 :
                    	    // /home/hasitha/Desktop/ToSend/SampleProject/src/main/java/a.g:75:36: ',' p+= formalParameter
                    	    {
                    	    match(input,9,FOLLOW_9_in_function289); if (state.failed) return retval;
                    	    pushFollow(FOLLOW_formalParameter_in_function293);
                    	    p=formalParameter();

                    	    state._fsp--;
                    	    if (state.failed) return retval;
                    	    if (list_p==null) list_p=new ArrayList();
                    	    list_p.add(p.getTemplate());


                    	    }
                    	    break;

                    	default :
                    	    break loop3;
                        }
                    } while (true);


                    }
                    break;

            }

            match(input,10,FOLLOW_10_in_function301); if (state.failed) return retval;
            pushFollow(FOLLOW_block_in_function311);
            block();

            state._fsp--;
            if (state.failed) return retval;


            // TEMPLATE REWRITE
            if ( state.backtracking==0 ) {
              // 77:2: -> {\"main\".equalsIgnoreCase($function::name)}? main_function(type=$type.stname=\"main\"locals=$slist::localsstats=$slist::statsargs=$p)
              if ("main".equalsIgnoreCase(((function_scope)function_stack.peek()).name)) {
                  retval.st = templateLib.getInstanceOf("main_function",
                new STAttrMap().put("type", (type6!=null?type6.st:null)).put("name", "main").put("locals", ((slist_scope)slist_stack.peek()).locals).put("stats", ((slist_scope)slist_stack.peek()).stats).put("args", list_p));
              }
              else // 82:9: -> function(type=$type.stname=$function::namelocals=$slist::localsstats=$slist::statsargs=$p)
              {
                  retval.st = templateLib.getInstanceOf("function",
                new STAttrMap().put("type", (type6!=null?type6.st:null)).put("name", ((function_scope)function_stack.peek()).name).put("locals", ((slist_scope)slist_stack.peek()).locals).put("stats", ((slist_scope)slist_stack.peek()).stats).put("args", list_p));
              }

            }
            }

            retval.stop = input.LT(-1);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
            slist_stack.pop();
            function_stack.pop();
        }
        return retval;
    }
    // $ANTLR end "function"

    public static class formalParameter_return extends ParserRuleReturnScope {
        public StringTemplate st;
        public Object getTemplate() { return st; }
        public String toString() { return st==null?null:st.toString(); }
    };

    // $ANTLR start "formalParameter"
    // /home/hasitha/Desktop/ToSend/SampleProject/src/main/java/a.g:88:1: formalParameter : type declarator -> parameter(type=$type.stname=$declarator.st);
    public final aParser.formalParameter_return formalParameter() throws RecognitionException {
        aParser.formalParameter_return retval = new aParser.formalParameter_return();
        retval.start = input.LT(1);

        aParser.type_return type7 = null;

        aParser.declarator_return declarator8 = null;


        try {
            // /home/hasitha/Desktop/ToSend/SampleProject/src/main/java/a.g:89:5: ( type declarator -> parameter(type=$type.stname=$declarator.st))
            // /home/hasitha/Desktop/ToSend/SampleProject/src/main/java/a.g:89:9: type declarator
            {
            pushFollow(FOLLOW_type_in_formalParameter529);
            type7=type();

            state._fsp--;
            if (state.failed) return retval;
            pushFollow(FOLLOW_declarator_in_formalParameter531);
            declarator8=declarator();

            state._fsp--;
            if (state.failed) return retval;


            // TEMPLATE REWRITE
            if ( state.backtracking==0 ) {
              // 90:9: -> parameter(type=$type.stname=$declarator.st)
              {
                  retval.st = templateLib.getInstanceOf("parameter",
                new STAttrMap().put("type", (type7!=null?type7.st:null)).put("name", (declarator8!=null?declarator8.st:null)));
              }

            }
            }

            retval.stop = input.LT(-1);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return retval;
    }
    // $ANTLR end "formalParameter"

    public static class type_return extends ParserRuleReturnScope {
        public StringTemplate st;
        public Object getTemplate() { return st; }
        public String toString() { return st==null?null:st.toString(); }
    };

    // $ANTLR start "type"
    // /home/hasitha/Desktop/ToSend/SampleProject/src/main/java/a.g:93:1: type : ( 'int' -> type_int() | 'char' -> type_char() | ID -> type_user_object(name=$ID.text));
    public final aParser.type_return type() throws RecognitionException {
        aParser.type_return retval = new aParser.type_return();
        retval.start = input.LT(1);

        Token ID9=null;

        try {
            // /home/hasitha/Desktop/ToSend/SampleProject/src/main/java/a.g:94:5: ( 'int' -> type_int() | 'char' -> type_char() | ID -> type_user_object(name=$ID.text))
            int alt5=3;
            switch ( input.LA(1) ) {
            case 11:
                {
                alt5=1;
                }
                break;
            case 12:
                {
                alt5=2;
                }
                break;
            case ID:
                {
                alt5=3;
                }
                break;
            default:
                if (state.backtracking>0) {state.failed=true; return retval;}
                NoViableAltException nvae =
                    new NoViableAltException("", 5, 0, input);

                throw nvae;
            }

            switch (alt5) {
                case 1 :
                    // /home/hasitha/Desktop/ToSend/SampleProject/src/main/java/a.g:94:9: 'int'
                    {
                    match(input,11,FOLLOW_11_in_type572); if (state.failed) return retval;


                    // TEMPLATE REWRITE
                    if ( state.backtracking==0 ) {
                      // 94:16: -> type_int()
                      {
                          retval.st = templateLib.getInstanceOf("type_int");
                      }

                    }
                    }
                    break;
                case 2 :
                    // /home/hasitha/Desktop/ToSend/SampleProject/src/main/java/a.g:95:9: 'char'
                    {
                    match(input,12,FOLLOW_12_in_type589); if (state.failed) return retval;


                    // TEMPLATE REWRITE
                    if ( state.backtracking==0 ) {
                      // 95:16: -> type_char()
                      {
                          retval.st = templateLib.getInstanceOf("type_char");
                      }

                    }
                    }
                    break;
                case 3 :
                    // /home/hasitha/Desktop/ToSend/SampleProject/src/main/java/a.g:96:9: ID
                    {
                    ID9=(Token)match(input,ID,FOLLOW_ID_in_type605); if (state.failed) return retval;


                    // TEMPLATE REWRITE
                    if ( state.backtracking==0 ) {
                      // 96:16: -> type_user_object(name=$ID.text)
                      {
                          retval.st = templateLib.getInstanceOf("type_user_object",
                        new STAttrMap().put("name", (ID9!=null?ID9.getText():null)));
                      }

                    }
                    }
                    break;

            }
            retval.stop = input.LT(-1);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return retval;
    }
    // $ANTLR end "type"

    public static class block_return extends ParserRuleReturnScope {
        public StringTemplate st;
        public Object getTemplate() { return st; }
        public String toString() { return st==null?null:st.toString(); }
    };

    // $ANTLR start "block"
    // /home/hasitha/Desktop/ToSend/SampleProject/src/main/java/a.g:99:1: block : '{' ( variable )* ( stat )* '}' ;
    public final aParser.block_return block() throws RecognitionException {
        aParser.block_return retval = new aParser.block_return();
        retval.start = input.LT(1);

        aParser.variable_return variable10 = null;

        aParser.stat_return stat11 = null;


        try {
            // /home/hasitha/Desktop/ToSend/SampleProject/src/main/java/a.g:100:5: ( '{' ( variable )* ( stat )* '}' )
            // /home/hasitha/Desktop/ToSend/SampleProject/src/main/java/a.g:100:8: '{' ( variable )* ( stat )* '}'
            {
            match(input,13,FOLLOW_13_in_block636); if (state.failed) return retval;
            // /home/hasitha/Desktop/ToSend/SampleProject/src/main/java/a.g:101:8: ( variable )*
            loop6:
            do {
                int alt6=2;
                int LA6_0 = input.LA(1);

                if ( (LA6_0==ID) ) {
                    int LA6_2 = input.LA(2);

                    if ( (LA6_2==ID) ) {
                        alt6=1;
                    }


                }
                else if ( ((LA6_0>=11 && LA6_0<=12)) ) {
                    alt6=1;
                }


                switch (alt6) {
            	case 1 :
            	    // /home/hasitha/Desktop/ToSend/SampleProject/src/main/java/a.g:101:10: variable
            	    {
            	    pushFollow(FOLLOW_variable_in_block647);
            	    variable10=variable();

            	    state._fsp--;
            	    if (state.failed) return retval;
            	    if ( state.backtracking==0 ) {
            	      ((slist_scope)slist_stack.peek()).locals.add((variable10!=null?variable10.st:null));
            	    }

            	    }
            	    break;

            	default :
            	    break loop6;
                }
            } while (true);

            // /home/hasitha/Desktop/ToSend/SampleProject/src/main/java/a.g:102:8: ( stat )*
            loop7:
            do {
                int alt7=2;
                int LA7_0 = input.LA(1);

                if ( ((LA7_0>=ID && LA7_0<=INT)||(LA7_0>=7 && LA7_0<=8)||LA7_0==13||(LA7_0>=15 && LA7_0<=17)) ) {
                    alt7=1;
                }


                switch (alt7) {
            	case 1 :
            	    // /home/hasitha/Desktop/ToSend/SampleProject/src/main/java/a.g:102:10: stat
            	    {
            	    pushFollow(FOLLOW_stat_in_block663);
            	    stat11=stat();

            	    state._fsp--;
            	    if (state.failed) return retval;
            	    if ( state.backtracking==0 ) {
            	      ((slist_scope)slist_stack.peek()).stats.add((stat11!=null?stat11.st:null));
            	    }

            	    }
            	    break;

            	default :
            	    break loop7;
                }
            } while (true);

            match(input,14,FOLLOW_14_in_block676); if (state.failed) return retval;

            }

            retval.stop = input.LT(-1);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return retval;
    }
    // $ANTLR end "block"

    public static class stat_return extends ParserRuleReturnScope {
        public StringTemplate st;
        public Object getTemplate() { return st; }
        public String toString() { return st==null?null:st.toString(); }
    };

    // $ANTLR start "stat"
    // /home/hasitha/Desktop/ToSend/SampleProject/src/main/java/a.g:106:1: stat : ( forStat -> {$forStat.st} | whileStat -> {$whileStat.st} | dowhileStat -> {$dowhileStat.st} | expr ';' -> statement(expr=$expr.st) | block -> statementList(locals=$slist::localsstats=$slist::stats) | assignStat ';' -> {$assignStat.st} | ';' -> {new StringTemplate(\";\")});
    public final aParser.stat_return stat() throws RecognitionException {
        slist_stack.push(new slist_scope());

        aParser.stat_return retval = new aParser.stat_return();
        retval.start = input.LT(1);

        aParser.forStat_return forStat12 = null;

        aParser.whileStat_return whileStat13 = null;

        aParser.dowhileStat_return dowhileStat14 = null;

        aParser.expr_return expr15 = null;

        aParser.assignStat_return assignStat16 = null;



          ((slist_scope)slist_stack.peek()).locals = new ArrayList();
          ((slist_scope)slist_stack.peek()).stats = new ArrayList();

        try {
            // /home/hasitha/Desktop/ToSend/SampleProject/src/main/java/a.g:112:5: ( forStat -> {$forStat.st} | whileStat -> {$whileStat.st} | dowhileStat -> {$dowhileStat.st} | expr ';' -> statement(expr=$expr.st) | block -> statementList(locals=$slist::localsstats=$slist::stats) | assignStat ';' -> {$assignStat.st} | ';' -> {new StringTemplate(\";\")})
            int alt8=7;
            switch ( input.LA(1) ) {
            case 15:
                {
                alt8=1;
                }
                break;
            case 16:
                {
                alt8=2;
                }
                break;
            case 17:
                {
                alt8=3;
                }
                break;
            case ID:
                {
                int LA8_4 = input.LA(2);

                if ( (LA8_4==18) ) {
                    alt8=6;
                }
                else if ( (LA8_4==7||(LA8_4>=19 && LA8_4<=21)) ) {
                    alt8=4;
                }
                else {
                    if (state.backtracking>0) {state.failed=true; return retval;}
                    NoViableAltException nvae =
                        new NoViableAltException("", 8, 4, input);

                    throw nvae;
                }
                }
                break;
            case INT:
            case 8:
                {
                alt8=4;
                }
                break;
            case 13:
                {
                alt8=5;
                }
                break;
            case 7:
                {
                alt8=7;
                }
                break;
            default:
                if (state.backtracking>0) {state.failed=true; return retval;}
                NoViableAltException nvae =
                    new NoViableAltException("", 8, 0, input);

                throw nvae;
            }

            switch (alt8) {
                case 1 :
                    // /home/hasitha/Desktop/ToSend/SampleProject/src/main/java/a.g:112:7: forStat
                    {
                    pushFollow(FOLLOW_forStat_in_stat703);
                    forStat12=forStat();

                    state._fsp--;
                    if (state.failed) return retval;


                    // TEMPLATE REWRITE
                    if ( state.backtracking==0 ) {
                      // 112:15: -> {$forStat.st}
                      {
                          retval.st = (forStat12!=null?forStat12.st:null);
                      }

                    }
                    }
                    break;
                case 2 :
                    // /home/hasitha/Desktop/ToSend/SampleProject/src/main/java/a.g:113:7: whileStat
                    {
                    pushFollow(FOLLOW_whileStat_in_stat715);
                    whileStat13=whileStat();

                    state._fsp--;
                    if (state.failed) return retval;


                    // TEMPLATE REWRITE
                    if ( state.backtracking==0 ) {
                      // 113:17: -> {$whileStat.st}
                      {
                          retval.st = (whileStat13!=null?whileStat13.st:null);
                      }

                    }
                    }
                    break;
                case 3 :
                    // /home/hasitha/Desktop/ToSend/SampleProject/src/main/java/a.g:114:7: dowhileStat
                    {
                    pushFollow(FOLLOW_dowhileStat_in_stat727);
                    dowhileStat14=dowhileStat();

                    state._fsp--;
                    if (state.failed) return retval;


                    // TEMPLATE REWRITE
                    if ( state.backtracking==0 ) {
                      // 114:19: -> {$dowhileStat.st}
                      {
                          retval.st = (dowhileStat14!=null?dowhileStat14.st:null);
                      }

                    }
                    }
                    break;
                case 4 :
                    // /home/hasitha/Desktop/ToSend/SampleProject/src/main/java/a.g:115:7: expr ';'
                    {
                    pushFollow(FOLLOW_expr_in_stat739);
                    expr15=expr();

                    state._fsp--;
                    if (state.failed) return retval;
                    match(input,7,FOLLOW_7_in_stat741); if (state.failed) return retval;


                    // TEMPLATE REWRITE
                    if ( state.backtracking==0 ) {
                      // 115:16: -> statement(expr=$expr.st)
                      {
                          retval.st = templateLib.getInstanceOf("statement",
                        new STAttrMap().put("expr", (expr15!=null?expr15.st:null)));
                      }

                    }
                    }
                    break;
                case 5 :
                    // /home/hasitha/Desktop/ToSend/SampleProject/src/main/java/a.g:116:7: block
                    {
                    pushFollow(FOLLOW_block_in_stat758);
                    block();

                    state._fsp--;
                    if (state.failed) return retval;


                    // TEMPLATE REWRITE
                    if ( state.backtracking==0 ) {
                      // 116:13: -> statementList(locals=$slist::localsstats=$slist::stats)
                      {
                          retval.st = templateLib.getInstanceOf("statementList",
                        new STAttrMap().put("locals", ((slist_scope)slist_stack.peek()).locals).put("stats", ((slist_scope)slist_stack.peek()).stats));
                      }

                    }
                    }
                    break;
                case 6 :
                    // /home/hasitha/Desktop/ToSend/SampleProject/src/main/java/a.g:117:7: assignStat ';'
                    {
                    pushFollow(FOLLOW_assignStat_in_stat780);
                    assignStat16=assignStat();

                    state._fsp--;
                    if (state.failed) return retval;
                    match(input,7,FOLLOW_7_in_stat782); if (state.failed) return retval;


                    // TEMPLATE REWRITE
                    if ( state.backtracking==0 ) {
                      // 117:22: -> {$assignStat.st}
                      {
                          retval.st = (assignStat16!=null?assignStat16.st:null);
                      }

                    }
                    }
                    break;
                case 7 :
                    // /home/hasitha/Desktop/ToSend/SampleProject/src/main/java/a.g:118:7: ';'
                    {
                    match(input,7,FOLLOW_7_in_stat794); if (state.failed) return retval;


                    // TEMPLATE REWRITE
                    if ( state.backtracking==0 ) {
                      // 118:11: -> {new StringTemplate(\";\")}
                      {
                          retval.st = new StringTemplate(";");
                      }

                    }
                    }
                    break;

            }
            retval.stop = input.LT(-1);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
            slist_stack.pop();

        }
        return retval;
    }
    // $ANTLR end "stat"

    public static class forStat_return extends ParserRuleReturnScope {
        public StringTemplate st;
        public Object getTemplate() { return st; }
        public String toString() { return st==null?null:st.toString(); }
    };

    // $ANTLR start "forStat"
    // /home/hasitha/Desktop/ToSend/SampleProject/src/main/java/a.g:121:1: forStat : 'for' '(' e1= assignStat ';' e2= expr ';' e3= assignStat ')' block -> forLoop(name=$function::namelcount=$function::loopcounte1=$e1.ste2=$e2.ste3=$e3.stlocals=$slist::localsstats=$slist::stats);
    public final aParser.forStat_return forStat() throws RecognitionException {
        slist_stack.push(new slist_scope());

        aParser.forStat_return retval = new aParser.forStat_return();
        retval.start = input.LT(1);

        aParser.assignStat_return e1 = null;

        aParser.expr_return e2 = null;

        aParser.assignStat_return e3 = null;



          ((slist_scope)slist_stack.peek()).locals = new ArrayList();
          ((slist_scope)slist_stack.peek()).stats = new ArrayList();

        try {
            // /home/hasitha/Desktop/ToSend/SampleProject/src/main/java/a.g:127:5: ( 'for' '(' e1= assignStat ';' e2= expr ';' e3= assignStat ')' block -> forLoop(name=$function::namelcount=$function::loopcounte1=$e1.ste2=$e2.ste3=$e3.stlocals=$slist::localsstats=$slist::stats))
            // /home/hasitha/Desktop/ToSend/SampleProject/src/main/java/a.g:127:9: 'for' '(' e1= assignStat ';' e2= expr ';' e3= assignStat ')' block
            {
            match(input,15,FOLLOW_15_in_forStat827); if (state.failed) return retval;
            match(input,8,FOLLOW_8_in_forStat829); if (state.failed) return retval;
            pushFollow(FOLLOW_assignStat_in_forStat833);
            e1=assignStat();

            state._fsp--;
            if (state.failed) return retval;
            match(input,7,FOLLOW_7_in_forStat835); if (state.failed) return retval;
            pushFollow(FOLLOW_expr_in_forStat839);
            e2=expr();

            state._fsp--;
            if (state.failed) return retval;
            match(input,7,FOLLOW_7_in_forStat841); if (state.failed) return retval;
            pushFollow(FOLLOW_assignStat_in_forStat845);
            e3=assignStat();

            state._fsp--;
            if (state.failed) return retval;
            match(input,10,FOLLOW_10_in_forStat847); if (state.failed) return retval;
            pushFollow(FOLLOW_block_in_forStat849);
            block();

            state._fsp--;
            if (state.failed) return retval;
            if ( state.backtracking==0 ) {
              ((function_scope)function_stack.peek()).loopcount = ((function_scope)function_stack.peek()).loopcount + 1;
            }


            // TEMPLATE REWRITE
            if ( state.backtracking==0 ) {
              // 128:9: -> forLoop(name=$function::namelcount=$function::loopcounte1=$e1.ste2=$e2.ste3=$e3.stlocals=$slist::localsstats=$slist::stats)
              {
                  retval.st = templateLib.getInstanceOf("forLoop",
                new STAttrMap().put("name", ((function_scope)function_stack.peek()).name).put("lcount", ((function_scope)function_stack.peek()).loopcount).put("e1", (e1!=null?e1.st:null)).put("e2", (e2!=null?e2.st:null)).put("e3", (e3!=null?e3.st:null)).put("locals", ((slist_scope)slist_stack.peek()).locals).put("stats", ((slist_scope)slist_stack.peek()).stats));
              }

            }
            }

            retval.stop = input.LT(-1);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
            slist_stack.pop();

        }
        return retval;
    }
    // $ANTLR end "forStat"

    public static class whileStat_return extends ParserRuleReturnScope {
        public StringTemplate st;
        public Object getTemplate() { return st; }
        public String toString() { return st==null?null:st.toString(); }
    };

    // $ANTLR start "whileStat"
    // /home/hasitha/Desktop/ToSend/SampleProject/src/main/java/a.g:132:1: whileStat : 'while' '(' e2= expr ')' block -> whileLoop(name=$function::namelcount=$function::loopcounte2=$e2.stlocals=$slist::localsstats=$slist::stats);
    public final aParser.whileStat_return whileStat() throws RecognitionException {
        slist_stack.push(new slist_scope());

        aParser.whileStat_return retval = new aParser.whileStat_return();
        retval.start = input.LT(1);

        aParser.expr_return e2 = null;



          ((slist_scope)slist_stack.peek()).locals = new ArrayList();
          ((slist_scope)slist_stack.peek()).stats = new ArrayList();

        try {
            // /home/hasitha/Desktop/ToSend/SampleProject/src/main/java/a.g:138:5: ( 'while' '(' e2= expr ')' block -> whileLoop(name=$function::namelcount=$function::loopcounte2=$e2.stlocals=$slist::localsstats=$slist::stats))
            // /home/hasitha/Desktop/ToSend/SampleProject/src/main/java/a.g:138:9: 'while' '(' e2= expr ')' block
            {
            match(input,16,FOLLOW_16_in_whileStat942); if (state.failed) return retval;
            match(input,8,FOLLOW_8_in_whileStat944); if (state.failed) return retval;
            pushFollow(FOLLOW_expr_in_whileStat948);
            e2=expr();

            state._fsp--;
            if (state.failed) return retval;
            match(input,10,FOLLOW_10_in_whileStat950); if (state.failed) return retval;
            pushFollow(FOLLOW_block_in_whileStat952);
            block();

            state._fsp--;
            if (state.failed) return retval;
            if ( state.backtracking==0 ) {
              ((function_scope)function_stack.peek()).loopcount = ((function_scope)function_stack.peek()).loopcount + 1;
            }


            // TEMPLATE REWRITE
            if ( state.backtracking==0 ) {
              // 139:9: -> whileLoop(name=$function::namelcount=$function::loopcounte2=$e2.stlocals=$slist::localsstats=$slist::stats)
              {
                  retval.st = templateLib.getInstanceOf("whileLoop",
                new STAttrMap().put("name", ((function_scope)function_stack.peek()).name).put("lcount", ((function_scope)function_stack.peek()).loopcount).put("e2", (e2!=null?e2.st:null)).put("locals", ((slist_scope)slist_stack.peek()).locals).put("stats", ((slist_scope)slist_stack.peek()).stats));
              }

            }
            }

            retval.stop = input.LT(-1);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
            slist_stack.pop();

        }
        return retval;
    }
    // $ANTLR end "whileStat"

    public static class dowhileStat_return extends ParserRuleReturnScope {
        public StringTemplate st;
        public Object getTemplate() { return st; }
        public String toString() { return st==null?null:st.toString(); }
    };

    // $ANTLR start "dowhileStat"
    // /home/hasitha/Desktop/ToSend/SampleProject/src/main/java/a.g:143:1: dowhileStat : 'do' block 'while' '(' e2= expr ')' ';' -> dowhileLoop(name=$function::namelcount=$function::loopcounte2=$e2.stlocals=$slist::localsstats=$slist::stats);
    public final aParser.dowhileStat_return dowhileStat() throws RecognitionException {
        slist_stack.push(new slist_scope());

        aParser.dowhileStat_return retval = new aParser.dowhileStat_return();
        retval.start = input.LT(1);

        aParser.expr_return e2 = null;



          ((slist_scope)slist_stack.peek()).locals = new ArrayList();
          ((slist_scope)slist_stack.peek()).stats = new ArrayList();

        try {
            // /home/hasitha/Desktop/ToSend/SampleProject/src/main/java/a.g:149:5: ( 'do' block 'while' '(' e2= expr ')' ';' -> dowhileLoop(name=$function::namelcount=$function::loopcounte2=$e2.stlocals=$slist::localsstats=$slist::stats))
            // /home/hasitha/Desktop/ToSend/SampleProject/src/main/java/a.g:149:9: 'do' block 'while' '(' e2= expr ')' ';'
            {
            match(input,17,FOLLOW_17_in_dowhileStat1037); if (state.failed) return retval;
            pushFollow(FOLLOW_block_in_dowhileStat1039);
            block();

            state._fsp--;
            if (state.failed) return retval;
            match(input,16,FOLLOW_16_in_dowhileStat1041); if (state.failed) return retval;
            match(input,8,FOLLOW_8_in_dowhileStat1043); if (state.failed) return retval;
            pushFollow(FOLLOW_expr_in_dowhileStat1047);
            e2=expr();

            state._fsp--;
            if (state.failed) return retval;
            match(input,10,FOLLOW_10_in_dowhileStat1049); if (state.failed) return retval;
            match(input,7,FOLLOW_7_in_dowhileStat1051); if (state.failed) return retval;
            if ( state.backtracking==0 ) {
              ((function_scope)function_stack.peek()).loopcount = ((function_scope)function_stack.peek()).loopcount + 1;
            }


            // TEMPLATE REWRITE
            if ( state.backtracking==0 ) {
              // 150:9: -> dowhileLoop(name=$function::namelcount=$function::loopcounte2=$e2.stlocals=$slist::localsstats=$slist::stats)
              {
                  retval.st = templateLib.getInstanceOf("dowhileLoop",
                new STAttrMap().put("name", ((function_scope)function_stack.peek()).name).put("lcount", ((function_scope)function_stack.peek()).loopcount).put("e2", (e2!=null?e2.st:null)).put("locals", ((slist_scope)slist_stack.peek()).locals).put("stats", ((slist_scope)slist_stack.peek()).stats));
              }

            }
            }

            retval.stop = input.LT(-1);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
            slist_stack.pop();

        }
        return retval;
    }
    // $ANTLR end "dowhileStat"

    public static class assignStat_return extends ParserRuleReturnScope {
        public StringTemplate st;
        public Object getTemplate() { return st; }
        public String toString() { return st==null?null:st.toString(); }
    };

    // $ANTLR start "assignStat"
    // /home/hasitha/Desktop/ToSend/SampleProject/src/main/java/a.g:154:1: assignStat : a= ID '=' (b= INT -> assignID(lhs=$a.textrhs=$b.text) | expr -> assign(lhs=$a.textrhs=$expr.st)) ;
    public final aParser.assignStat_return assignStat() throws RecognitionException {
        aParser.assignStat_return retval = new aParser.assignStat_return();
        retval.start = input.LT(1);

        Token a=null;
        Token b=null;
        aParser.expr_return expr17 = null;


        try {
            // /home/hasitha/Desktop/ToSend/SampleProject/src/main/java/a.g:155:5: (a= ID '=' (b= INT -> assignID(lhs=$a.textrhs=$b.text) | expr -> assign(lhs=$a.textrhs=$expr.st)) )
            // /home/hasitha/Desktop/ToSend/SampleProject/src/main/java/a.g:155:9: a= ID '=' (b= INT -> assignID(lhs=$a.textrhs=$b.text) | expr -> assign(lhs=$a.textrhs=$expr.st))
            {
            a=(Token)match(input,ID,FOLLOW_ID_in_assignStat1128); if (state.failed) return retval;
            match(input,18,FOLLOW_18_in_assignStat1131); if (state.failed) return retval;
            // /home/hasitha/Desktop/ToSend/SampleProject/src/main/java/a.g:156:6: (b= INT -> assignID(lhs=$a.textrhs=$b.text) | expr -> assign(lhs=$a.textrhs=$expr.st))
            int alt9=2;
            int LA9_0 = input.LA(1);

            if ( (LA9_0==INT) ) {
                int LA9_1 = input.LA(2);

                if ( (synpred15_a()) ) {
                    alt9=1;
                }
                else if ( (true) ) {
                    alt9=2;
                }
                else {
                    if (state.backtracking>0) {state.failed=true; return retval;}
                    NoViableAltException nvae =
                        new NoViableAltException("", 9, 1, input);

                    throw nvae;
                }
            }
            else if ( (LA9_0==ID||LA9_0==8) ) {
                alt9=2;
            }
            else {
                if (state.backtracking>0) {state.failed=true; return retval;}
                NoViableAltException nvae =
                    new NoViableAltException("", 9, 0, input);

                throw nvae;
            }
            switch (alt9) {
                case 1 :
                    // /home/hasitha/Desktop/ToSend/SampleProject/src/main/java/a.g:156:8: b= INT
                    {
                    b=(Token)match(input,INT,FOLLOW_INT_in_assignStat1144); if (state.failed) return retval;


                    // TEMPLATE REWRITE
                    if ( state.backtracking==0 ) {
                      // 156:14: -> assignID(lhs=$a.textrhs=$b.text)
                      {
                          retval.st = templateLib.getInstanceOf("assignID",
                        new STAttrMap().put("lhs", (a!=null?a.getText():null)).put("rhs", (b!=null?b.getText():null)));
                      }

                    }
                    }
                    break;
                case 2 :
                    // /home/hasitha/Desktop/ToSend/SampleProject/src/main/java/a.g:157:10: expr
                    {
                    pushFollow(FOLLOW_expr_in_assignStat1169);
                    expr17=expr();

                    state._fsp--;
                    if (state.failed) return retval;


                    // TEMPLATE REWRITE
                    if ( state.backtracking==0 ) {
                      // 157:15: -> assign(lhs=$a.textrhs=$expr.st)
                      {
                          retval.st = templateLib.getInstanceOf("assign",
                        new STAttrMap().put("lhs", (a!=null?a.getText():null)).put("rhs", (expr17!=null?expr17.st:null)));
                      }

                    }
                    }
                    break;

            }


            }

            retval.stop = input.LT(-1);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return retval;
    }
    // $ANTLR end "assignStat"

    public static class expr_return extends ParserRuleReturnScope {
        public StringTemplate st;
        public Object getTemplate() { return st; }
        public String toString() { return st==null?null:st.toString(); }
    };

    // $ANTLR start "expr"
    // /home/hasitha/Desktop/ToSend/SampleProject/src/main/java/a.g:160:1: expr : condExpr -> {$condExpr.st};
    public final aParser.expr_return expr() throws RecognitionException {
        aParser.expr_return retval = new aParser.expr_return();
        retval.start = input.LT(1);

        aParser.condExpr_return condExpr18 = null;


        try {
            // /home/hasitha/Desktop/ToSend/SampleProject/src/main/java/a.g:160:5: ( condExpr -> {$condExpr.st})
            // /home/hasitha/Desktop/ToSend/SampleProject/src/main/java/a.g:160:9: condExpr
            {
            pushFollow(FOLLOW_condExpr_in_expr1199);
            condExpr18=condExpr();

            state._fsp--;
            if (state.failed) return retval;


            // TEMPLATE REWRITE
            if ( state.backtracking==0 ) {
              // 160:18: -> {$condExpr.st}
              {
                  retval.st = (condExpr18!=null?condExpr18.st:null);
              }

            }
            }

            retval.stop = input.LT(-1);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return retval;
    }
    // $ANTLR end "expr"

    public static class condExpr_return extends ParserRuleReturnScope {
        public StringTemplate st;
        public Object getTemplate() { return st; }
        public String toString() { return st==null?null:st.toString(); }
    };

    // $ANTLR start "condExpr"
    // /home/hasitha/Desktop/ToSend/SampleProject/src/main/java/a.g:163:1: condExpr : a= aexpr ( ( '==' b= aexpr -> equals(left=$a.stright=$b.st) | '<' b= aexpr -> lessThan(left=$a.stright=$b.st)) | -> {$a.st}) ;
    public final aParser.condExpr_return condExpr() throws RecognitionException {
        aParser.condExpr_return retval = new aParser.condExpr_return();
        retval.start = input.LT(1);

        aParser.aexpr_return a = null;

        aParser.aexpr_return b = null;


        try {
            // /home/hasitha/Desktop/ToSend/SampleProject/src/main/java/a.g:164:5: (a= aexpr ( ( '==' b= aexpr -> equals(left=$a.stright=$b.st) | '<' b= aexpr -> lessThan(left=$a.stright=$b.st)) | -> {$a.st}) )
            // /home/hasitha/Desktop/ToSend/SampleProject/src/main/java/a.g:164:9: a= aexpr ( ( '==' b= aexpr -> equals(left=$a.stright=$b.st) | '<' b= aexpr -> lessThan(left=$a.stright=$b.st)) | -> {$a.st})
            {
            pushFollow(FOLLOW_aexpr_in_condExpr1224);
            a=aexpr();

            state._fsp--;
            if (state.failed) return retval;
            // /home/hasitha/Desktop/ToSend/SampleProject/src/main/java/a.g:165:9: ( ( '==' b= aexpr -> equals(left=$a.stright=$b.st) | '<' b= aexpr -> lessThan(left=$a.stright=$b.st)) | -> {$a.st})
            int alt11=2;
            int LA11_0 = input.LA(1);

            if ( ((LA11_0>=19 && LA11_0<=20)) ) {
                alt11=1;
            }
            else if ( (LA11_0==7||LA11_0==10) ) {
                alt11=2;
            }
            else {
                if (state.backtracking>0) {state.failed=true; return retval;}
                NoViableAltException nvae =
                    new NoViableAltException("", 11, 0, input);

                throw nvae;
            }
            switch (alt11) {
                case 1 :
                    // /home/hasitha/Desktop/ToSend/SampleProject/src/main/java/a.g:165:13: ( '==' b= aexpr -> equals(left=$a.stright=$b.st) | '<' b= aexpr -> lessThan(left=$a.stright=$b.st))
                    {
                    // /home/hasitha/Desktop/ToSend/SampleProject/src/main/java/a.g:165:13: ( '==' b= aexpr -> equals(left=$a.stright=$b.st) | '<' b= aexpr -> lessThan(left=$a.stright=$b.st))
                    int alt10=2;
                    int LA10_0 = input.LA(1);

                    if ( (LA10_0==19) ) {
                        alt10=1;
                    }
                    else if ( (LA10_0==20) ) {
                        alt10=2;
                    }
                    else {
                        if (state.backtracking>0) {state.failed=true; return retval;}
                        NoViableAltException nvae =
                            new NoViableAltException("", 10, 0, input);

                        throw nvae;
                    }
                    switch (alt10) {
                        case 1 :
                            // /home/hasitha/Desktop/ToSend/SampleProject/src/main/java/a.g:165:16: '==' b= aexpr
                            {
                            match(input,19,FOLLOW_19_in_condExpr1241); if (state.failed) return retval;
                            pushFollow(FOLLOW_aexpr_in_condExpr1245);
                            b=aexpr();

                            state._fsp--;
                            if (state.failed) return retval;


                            // TEMPLATE REWRITE
                            if ( state.backtracking==0 ) {
                              // 165:29: -> equals(left=$a.stright=$b.st)
                              {
                                  retval.st = templateLib.getInstanceOf("equals",
                                new STAttrMap().put("left", (a!=null?a.st:null)).put("right", (b!=null?b.st:null)));
                              }

                            }
                            }
                            break;
                        case 2 :
                            // /home/hasitha/Desktop/ToSend/SampleProject/src/main/java/a.g:166:16: '<' b= aexpr
                            {
                            match(input,20,FOLLOW_20_in_condExpr1275); if (state.failed) return retval;
                            pushFollow(FOLLOW_aexpr_in_condExpr1279);
                            b=aexpr();

                            state._fsp--;
                            if (state.failed) return retval;


                            // TEMPLATE REWRITE
                            if ( state.backtracking==0 ) {
                              // 166:30: -> lessThan(left=$a.stright=$b.st)
                              {
                                  retval.st = templateLib.getInstanceOf("lessThan",
                                new STAttrMap().put("left", (a!=null?a.st:null)).put("right", (b!=null?b.st:null)));
                              }

                            }
                            }
                            break;

                    }


                    }
                    break;
                case 2 :
                    // /home/hasitha/Desktop/ToSend/SampleProject/src/main/java/a.g:168:13: 
                    {

                    // TEMPLATE REWRITE
                    if ( state.backtracking==0 ) {
                      // 168:13: -> {$a.st}
                      {
                          retval.st = (a!=null?a.st:null);
                      }

                    }
                    }
                    break;

            }


            }

            retval.stop = input.LT(-1);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return retval;
    }
    // $ANTLR end "condExpr"

    public static class aexpr_return extends ParserRuleReturnScope {
        public StringTemplate st;
        public Object getTemplate() { return st; }
        public String toString() { return st==null?null:st.toString(); }
    };

    // $ANTLR start "aexpr"
    // /home/hasitha/Desktop/ToSend/SampleProject/src/main/java/a.g:172:1: aexpr : (a= atom -> {$a.st}) ( '+' b= INT -> add(left=$aexpr.stright=$b.text))* ;
    public final aParser.aexpr_return aexpr() throws RecognitionException {
        aParser.aexpr_return retval = new aParser.aexpr_return();
        retval.start = input.LT(1);

        Token b=null;
        aParser.atom_return a = null;


        try {
            // /home/hasitha/Desktop/ToSend/SampleProject/src/main/java/a.g:173:5: ( (a= atom -> {$a.st}) ( '+' b= INT -> add(left=$aexpr.stright=$b.text))* )
            // /home/hasitha/Desktop/ToSend/SampleProject/src/main/java/a.g:173:7: (a= atom -> {$a.st}) ( '+' b= INT -> add(left=$aexpr.stright=$b.text))*
            {
            // /home/hasitha/Desktop/ToSend/SampleProject/src/main/java/a.g:173:7: (a= atom -> {$a.st})
            // /home/hasitha/Desktop/ToSend/SampleProject/src/main/java/a.g:173:8: a= atom
            {
            pushFollow(FOLLOW_atom_in_aexpr1355);
            a=atom();

            state._fsp--;
            if (state.failed) return retval;


            // TEMPLATE REWRITE
            if ( state.backtracking==0 ) {
              // 173:15: -> {$a.st}
              {
                  retval.st = (a!=null?a.st:null);
              }

            }
            }

            // /home/hasitha/Desktop/ToSend/SampleProject/src/main/java/a.g:174:9: ( '+' b= INT -> add(left=$aexpr.stright=$b.text))*
            loop12:
            do {
                int alt12=2;
                int LA12_0 = input.LA(1);

                if ( (LA12_0==21) ) {
                    alt12=1;
                }


                switch (alt12) {
            	case 1 :
            	    // /home/hasitha/Desktop/ToSend/SampleProject/src/main/java/a.g:174:11: '+' b= INT
            	    {
            	    match(input,21,FOLLOW_21_in_aexpr1372); if (state.failed) return retval;
            	    b=(Token)match(input,INT,FOLLOW_INT_in_aexpr1376); if (state.failed) return retval;


            	    // TEMPLATE REWRITE
            	    if ( state.backtracking==0 ) {
            	      // 174:21: -> add(left=$aexpr.stright=$b.text)
            	      {
            	          retval.st = templateLib.getInstanceOf("add",
            	        new STAttrMap().put("left", retval.st).put("right", (b!=null?b.getText():null)));
            	      }

            	    }
            	    }
            	    break;

            	default :
            	    break loop12;
                }
            } while (true);


            }

            retval.stop = input.LT(-1);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return retval;
    }
    // $ANTLR end "aexpr"

    public static class atom_return extends ParserRuleReturnScope {
        public StringTemplate st;
        public Object getTemplate() { return st; }
        public String toString() { return st==null?null:st.toString(); }
    };

    // $ANTLR start "atom"
    // /home/hasitha/Desktop/ToSend/SampleProject/src/main/java/a.g:178:1: atom : ( ID -> refVar(id=$ID.text) | INT -> iconst(value=$INT.text) | '(' expr ')' -> {$expr.st});
    public final aParser.atom_return atom() throws RecognitionException {
        aParser.atom_return retval = new aParser.atom_return();
        retval.start = input.LT(1);

        Token ID19=null;
        Token INT20=null;
        aParser.expr_return expr21 = null;


        try {
            // /home/hasitha/Desktop/ToSend/SampleProject/src/main/java/a.g:179:5: ( ID -> refVar(id=$ID.text) | INT -> iconst(value=$INT.text) | '(' expr ')' -> {$expr.st})
            int alt13=3;
            switch ( input.LA(1) ) {
            case ID:
                {
                alt13=1;
                }
                break;
            case INT:
                {
                alt13=2;
                }
                break;
            case 8:
                {
                alt13=3;
                }
                break;
            default:
                if (state.backtracking>0) {state.failed=true; return retval;}
                NoViableAltException nvae =
                    new NoViableAltException("", 13, 0, input);

                throw nvae;
            }

            switch (alt13) {
                case 1 :
                    // /home/hasitha/Desktop/ToSend/SampleProject/src/main/java/a.g:179:7: ID
                    {
                    ID19=(Token)match(input,ID,FOLLOW_ID_in_atom1411); if (state.failed) return retval;


                    // TEMPLATE REWRITE
                    if ( state.backtracking==0 ) {
                      // 179:10: -> refVar(id=$ID.text)
                      {
                          retval.st = templateLib.getInstanceOf("refVar",
                        new STAttrMap().put("id", (ID19!=null?ID19.getText():null)));
                      }

                    }
                    }
                    break;
                case 2 :
                    // /home/hasitha/Desktop/ToSend/SampleProject/src/main/java/a.g:180:7: INT
                    {
                    INT20=(Token)match(input,INT,FOLLOW_INT_in_atom1428); if (state.failed) return retval;


                    // TEMPLATE REWRITE
                    if ( state.backtracking==0 ) {
                      // 180:11: -> iconst(value=$INT.text)
                      {
                          retval.st = templateLib.getInstanceOf("iconst",
                        new STAttrMap().put("value", (INT20!=null?INT20.getText():null)));
                      }

                    }
                    }
                    break;
                case 3 :
                    // /home/hasitha/Desktop/ToSend/SampleProject/src/main/java/a.g:181:7: '(' expr ')'
                    {
                    match(input,8,FOLLOW_8_in_atom1445); if (state.failed) return retval;
                    pushFollow(FOLLOW_expr_in_atom1447);
                    expr21=expr();

                    state._fsp--;
                    if (state.failed) return retval;
                    match(input,10,FOLLOW_10_in_atom1449); if (state.failed) return retval;


                    // TEMPLATE REWRITE
                    if ( state.backtracking==0 ) {
                      // 181:20: -> {$expr.st}
                      {
                          retval.st = (expr21!=null?expr21.st:null);
                      }

                    }
                    }
                    break;

            }
            retval.stop = input.LT(-1);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return retval;
    }
    // $ANTLR end "atom"

    // $ANTLR start synpred15_a
    public final void synpred15_a_fragment() throws RecognitionException {   
        Token b=null;

        // /home/hasitha/Desktop/ToSend/SampleProject/src/main/java/a.g:156:8: (b= INT )
        // /home/hasitha/Desktop/ToSend/SampleProject/src/main/java/a.g:156:8: b= INT
        {
        b=(Token)match(input,INT,FOLLOW_INT_in_synpred15_a1144); if (state.failed) return ;

        }
    }
    // $ANTLR end synpred15_a

    // Delegated rules

    public final boolean synpred15_a() {
        state.backtracking++;
        int start = input.mark();
        try {
            synpred15_a_fragment(); // can never throw exception
        } catch (RecognitionException re) {
            System.err.println("impossible: "+re);
        }
        boolean success = !state.failed;
        input.rewind(start);
        state.backtracking--;
        state.failed=false;
        return success;
    }


 

    public static final BitSet FOLLOW_declaration_in_program69 = new BitSet(new long[]{0x0000000000001812L});
    public static final BitSet FOLLOW_variable_in_declaration110 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_function_in_declaration126 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_type_in_variable150 = new BitSet(new long[]{0x0000000000000010L});
    public static final BitSet FOLLOW_declarator_in_variable152 = new BitSet(new long[]{0x0000000000000080L});
    public static final BitSet FOLLOW_7_in_variable154 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_ID_in_declarator228 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_type_in_function265 = new BitSet(new long[]{0x0000000000000010L});
    public static final BitSet FOLLOW_ID_in_function267 = new BitSet(new long[]{0x0000000000000100L});
    public static final BitSet FOLLOW_8_in_function279 = new BitSet(new long[]{0x0000000000001C10L});
    public static final BitSet FOLLOW_formalParameter_in_function285 = new BitSet(new long[]{0x0000000000000600L});
    public static final BitSet FOLLOW_9_in_function289 = new BitSet(new long[]{0x0000000000001810L});
    public static final BitSet FOLLOW_formalParameter_in_function293 = new BitSet(new long[]{0x0000000000000600L});
    public static final BitSet FOLLOW_10_in_function301 = new BitSet(new long[]{0x0000000000002000L});
    public static final BitSet FOLLOW_block_in_function311 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_type_in_formalParameter529 = new BitSet(new long[]{0x0000000000000010L});
    public static final BitSet FOLLOW_declarator_in_formalParameter531 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_11_in_type572 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_12_in_type589 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_ID_in_type605 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_13_in_block636 = new BitSet(new long[]{0x000000000003F9B0L});
    public static final BitSet FOLLOW_variable_in_block647 = new BitSet(new long[]{0x000000000003F9B0L});
    public static final BitSet FOLLOW_stat_in_block663 = new BitSet(new long[]{0x000000000003E1B0L});
    public static final BitSet FOLLOW_14_in_block676 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_forStat_in_stat703 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_whileStat_in_stat715 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_dowhileStat_in_stat727 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_expr_in_stat739 = new BitSet(new long[]{0x0000000000000080L});
    public static final BitSet FOLLOW_7_in_stat741 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_block_in_stat758 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_assignStat_in_stat780 = new BitSet(new long[]{0x0000000000000080L});
    public static final BitSet FOLLOW_7_in_stat782 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_7_in_stat794 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_15_in_forStat827 = new BitSet(new long[]{0x0000000000000100L});
    public static final BitSet FOLLOW_8_in_forStat829 = new BitSet(new long[]{0x0000000000000010L});
    public static final BitSet FOLLOW_assignStat_in_forStat833 = new BitSet(new long[]{0x0000000000000080L});
    public static final BitSet FOLLOW_7_in_forStat835 = new BitSet(new long[]{0x0000000000000130L});
    public static final BitSet FOLLOW_expr_in_forStat839 = new BitSet(new long[]{0x0000000000000080L});
    public static final BitSet FOLLOW_7_in_forStat841 = new BitSet(new long[]{0x0000000000000010L});
    public static final BitSet FOLLOW_assignStat_in_forStat845 = new BitSet(new long[]{0x0000000000000400L});
    public static final BitSet FOLLOW_10_in_forStat847 = new BitSet(new long[]{0x0000000000002000L});
    public static final BitSet FOLLOW_block_in_forStat849 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_16_in_whileStat942 = new BitSet(new long[]{0x0000000000000100L});
    public static final BitSet FOLLOW_8_in_whileStat944 = new BitSet(new long[]{0x0000000000000130L});
    public static final BitSet FOLLOW_expr_in_whileStat948 = new BitSet(new long[]{0x0000000000000400L});
    public static final BitSet FOLLOW_10_in_whileStat950 = new BitSet(new long[]{0x0000000000002000L});
    public static final BitSet FOLLOW_block_in_whileStat952 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_17_in_dowhileStat1037 = new BitSet(new long[]{0x0000000000002000L});
    public static final BitSet FOLLOW_block_in_dowhileStat1039 = new BitSet(new long[]{0x0000000000010000L});
    public static final BitSet FOLLOW_16_in_dowhileStat1041 = new BitSet(new long[]{0x0000000000000100L});
    public static final BitSet FOLLOW_8_in_dowhileStat1043 = new BitSet(new long[]{0x0000000000000130L});
    public static final BitSet FOLLOW_expr_in_dowhileStat1047 = new BitSet(new long[]{0x0000000000000400L});
    public static final BitSet FOLLOW_10_in_dowhileStat1049 = new BitSet(new long[]{0x0000000000000080L});
    public static final BitSet FOLLOW_7_in_dowhileStat1051 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_ID_in_assignStat1128 = new BitSet(new long[]{0x0000000000040000L});
    public static final BitSet FOLLOW_18_in_assignStat1131 = new BitSet(new long[]{0x0000000000000130L});
    public static final BitSet FOLLOW_INT_in_assignStat1144 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_expr_in_assignStat1169 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_condExpr_in_expr1199 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_aexpr_in_condExpr1224 = new BitSet(new long[]{0x0000000000180002L});
    public static final BitSet FOLLOW_19_in_condExpr1241 = new BitSet(new long[]{0x0000000000000130L});
    public static final BitSet FOLLOW_aexpr_in_condExpr1245 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_20_in_condExpr1275 = new BitSet(new long[]{0x0000000000000130L});
    public static final BitSet FOLLOW_aexpr_in_condExpr1279 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_atom_in_aexpr1355 = new BitSet(new long[]{0x0000000000200002L});
    public static final BitSet FOLLOW_21_in_aexpr1372 = new BitSet(new long[]{0x0000000000000020L});
    public static final BitSet FOLLOW_INT_in_aexpr1376 = new BitSet(new long[]{0x0000000000200002L});
    public static final BitSet FOLLOW_ID_in_atom1411 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_INT_in_atom1428 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_8_in_atom1445 = new BitSet(new long[]{0x0000000000000130L});
    public static final BitSet FOLLOW_expr_in_atom1447 = new BitSet(new long[]{0x0000000000000400L});
    public static final BitSet FOLLOW_10_in_atom1449 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_INT_in_synpred15_a1144 = new BitSet(new long[]{0x0000000000000002L});

}